<template>
    <div class="common-box" v-if="boxIsShow">
        <div class="common-content-box">
            <div class="common-content-bottom-box">
                <div class="table_search_box">
                    <el-form :inline="true" :model="searchForm" class="demo-form-inline">
                        <el-form-item>
                          <el-button type="danger" @click="addSameVideo(0)" size="small">新增</el-button>
                        </el-form-item>
                    </el-form>
                </div>
                <div class="table_box">
                    <el-table
                        :data="tableData"
                        stripe
                        style="width: 100%">
                        <el-table-column
                        label="标题"
                        width="200"
                        align="center">
                        <template slot-scope="scope">
                            {{ scope.row.title | truncate(30) }}
                        </template>
                        </el-table-column>
                        <el-table-column
                        label="标题"
                        width="500"
                        align="center">
                        <template slot-scope="scope">
                            {{ scope.row.wenan | truncate(100) }}
                        </template>
                        </el-table-column>
                        <el-table-column
                        label="操作"
                        align="center">
                        <template slot-scope="scope">
                            <el-button @click="playVideo(scope.row.videoUrl)" type="primary" size="small">查看视频</el-button>
                            <el-button @click="del(scope.row.id)" type="danger" size="small">删除</el-button>
                        </template>
                        </el-table-column>
                    </el-table>
                    <pagination
                    :total="total"
                    :limit="pageSize"
                    :page="pageNumber"
                    :pageSize="pageSize"
                    @pageChange="pageChange"
                    ></pagination>
                </div>
            </div>
        </div>
        <addSameVideo-box
          ref="addSameVideoBox"
          @close="
          getDataList();
          "
        ></addSameVideo-box>
    </div>
</template>
<script>
import Pagination from "@/components/pagination.vue";
import addSameVideoBox from "@/components/dialogbox/addSameVideoBox.vue";
export default {
    components: {
        Pagination,
        addSameVideoBox
    },
  data() {
    return {
        boxIsShow:false,
        total: 0,
        pageSize: 30,
        pageNumber: 1,
        tableData:[],
        sortList:[]
    };
  },
  created() {
    
  },
  mounted(){
    
  },
  filters: {
    truncate(value, maxLength) {
        if (!value) return "";
        if (value.length > maxLength) {
        return value.slice(0, maxLength) + "..."; // 截断并添加省略号
        }
        return value;
    }
},
  methods: {
    __init() {
      this.getDataList();
    },
    getDataList(){
      var url="manager/getAiSameByPage";
      var params={
        pageSize: this.pageSize,
        pageNum: this.pageNumber,
      }
      this.$post(url, params).then((res) => {
        console.log(res)
        if (res.code === 200) {
            this.tableData=res.data.list;
            this.total=res.data.total;
        } else {
          this.$message.error(res.msg)
        }
      });
    },
    pageChange(e) {
      this.pageNumber = e.page;
      this.getDataList();
    },
    resetForm(){
        this.searchForm={
            type:'',
            sortId:'',
            searchContent:""
        }
        this.pageNumber=1;
        this.getDataList();
    },
    search(){
      this.pageNumber=1;
      this.getDataList();
    },
    addSameVideo(id){
      if (this.$refs.addSameVideoBox) {
        this.$refs.addSameVideoBox.tkIsShow = true;
        this.$refs.addSameVideoBox.title = id==0?"新增":"编辑";
        this.$refs.addSameVideoBox.__init();
      }
    },
    del(id){
        this.$confirm('此操作将永久删除, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
            var url="manager/delAiSameById";
            var params={
                id: id
            }
            this.$post(url, params).then((res) => {
                console.log(res)
                if (res.code === 200) {
                    this.getDataList();
                    this.$message({
                        type: 'success',
                        message: '删除成功!'
                    });
                } else {
                this.$message.error(res.msg)
                }
            });
          
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });          
        });
    },
    playVideo(url){
        window.open(url);
    }
  }
}
</script>
<style scoped lang="scss">
  .common-box{
    background-color: #f9f9fb;
    height: 100%;
    position: relative;
  }
  .common-content-box{
    height: 95%;
    margin-top: 2%;
    width: 96%;
    display: inline-block;
  }
  .common-content-bottom-box{
    width: 100%;
    background-color: #fff;
    box-shadow: 1px 1px 6px 2px rgba(0, 0, 0, 0.1);
    border-radius: 5px;
    height: calc(100vh - 110px);
  }
  .table_search_box{
    text-align: left;
    width: 96%;
    margin-left: 2%;
    display: inline-block;
    margin-top: 20px;
  }
  .table_box{
    width: 96%;
    margin-left: 2%;
    height: calc(100% - 255px);
  }
</style>